import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { PetUtil } from "../info/PetUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { StringHelper } from "../../../../../com/gengine/utils/StringHelper";
import { MsgManager } from "../../../manager/MsgManager";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
//class PetSkillAlertWindow
    
    export  class PetSkillAlertWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(300, 220);
            this.titleHeight = 28;
            this.title = Language.getString(54049);
            this._bg = ObjCreate.createBg(17, 39, 264, 168, this);
            this._tipTxt = ObjCreate.createTextField("", 0, 50, 300, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.multiline = true;
            this._inputTipTxt = ObjCreate.createTextField("", 20, 100, 250, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._inputTipTxt.multiline = true;
            this._inputTipTxt.wordWrap = true;
            this._inputTipTxt.htmlText = "";
            this._inputTipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._delInput = ObjCreate.createGTextInput(80, 140, 135, 20, this);
            this._delInput.maxChars = 6;
            this._delInput.restrict = "A-z";
            this._okBtn = ObjCreate.createGButton(Language.getString(54065), 60, 170, 70, 27, this);
            this._okBtn.name = "ok";
            this._cancelBtn = ObjCreate.createGButton(Language.getString(54066), 160, 170, 70, 27, this);
            this._cancelBtn.name = "cancel";
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        public get petInfo(): SPetInfo
        {
            return this._petInfo;
        }

        public set petInfo(arg1: SPetInfo)
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this._tip = Language.getStringByParam(54067, PetUtil.getPetName(arg1));
                this._tipTxt.htmlText = this._tip;
            }
            return;
        }

        public setAlertSkill(arg1: Array<any>, arg2: Function): void
        {
            var loc2=null;
            var loc3=null;
            var loc1="";
            var loc4=0;
            while (loc4 < arg1.length) 
            {
                loc2 = arg1[loc4];
                loc3 = ColorConfig.instance.getItemColorString(loc2.skillLevel + 1);
                if (loc2.posType != 1) 
                {
                    if (loc4 != (arg1.length - 1)) 
                    {
                        loc1 = loc1 + (HTMLUtil.addColor(loc2.skillName, loc3) + "、");
                    }
                    else 
                    {
                        loc1 = loc1 + HTMLUtil.addColor(loc2.skillName, loc3);
                    }
                }
                ++loc4;
            }
            this._inputTipTxt.htmlText = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(Language.getStringByParam(54068, loc1), "#B1efff") + "</textFormat>";
            this._clickFun = arg2;
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=arg1.target as GButton;
            if (this._petInfo) 
            {
                if (loc1.name != "ok") 
                {
                    this.hide();
                }
                else 
                {
                    loc2 = this._delInput.text.toLocaleLowerCase();
                    if (StringHelper.getCharLength(StringHelper.trim(loc2)) == 0 || !(loc2 == "delete")) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54054));
                        return;
                    }
                    this.hide();
                }
                this._clickFun(loc1.name);
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._delInput.text = "";
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_delInput: GTextInput;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_inputTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_delTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_tip: string="";

        /* internal */ /* var */_clickFun: Function;
    }
